import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
export var getOpenKeysFromMenuData = function getOpenKeysFromMenuData(menuData) {
  return (menuData || []).reduce(function (pre, item) {
    if (item.key) {
      pre.push(item.key);
    }

    if (item.routes) {
      var newArray = pre.concat(getOpenKeysFromMenuData(item.routes) || []);
      return newArray;
    }

    return pre;
  }, []);
};
var themeConfig = {
  daybreak: '#1890ff',
  dust: '#F5222D',
  volcano: '#FA541C',
  sunset: '#FAAD14',
  cyan: '#13C2C2',
  green: '#52C41A',
  geekblue: '#2F54EB',
  purple: '#722ED1'
};
/**
 * Daybreak-> #1890ff
 *
 * @param val
 */

export function genStringToTheme(val) {
  return val && themeConfig[val] ? themeConfig[val] : val;
}
export function clearMenuItem(menusData) {
  return menusData.map(function (item) {
    var children = item.children || item.routes;

    var finalItem = _objectSpread({}, item);

    if (!finalItem.name || finalItem.hideInMenu) {
      return null;
    }

    if (finalItem && (finalItem === null || finalItem === void 0 ? void 0 : finalItem.routes)) {
      if (!finalItem.hideChildrenInMenu && children.some(function (child) {
        return child && child.name && !child.hideInMenu;
      })) {
        return _objectSpread(_objectSpread({}, item), {}, {
          children: clearMenuItem(children),
          routes: clearMenuItem(children)
        });
      } // children 为空就直接删掉


      delete finalItem.routes;
      delete finalItem.children;
    }

    return finalItem;
  }).filter(function (item) {
    return item;
  });
}